package com.gy.paidao.main;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.gy.paidao.BaseActivity;
import com.gy.paidao.R;
import com.gy.paidao.bean.BaseBean;
import com.gy.paidao.util.AnimUtil;
import com.gy.paidao.util.LogUtil;
import com.gy.paidao.util.SPHelper;
import com.gy.paidao.util.Urls;
import com.jky.struct2.http.core.AjaxParams;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 作者：gy on 16/4/17
 * 说明：举报
 */
public class ReportActivity extends BaseActivity {

    private ImageView img;
    private EditText etContent;
    private TextView tvSubmit;
    private String strContent;
    private String id,path;
    private int intoFlag;//举报标识
    private String userLoginID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentViewRes(R.layout.activity_report_layout);
        setViews();
    }

    @Override
    protected void initVariable() {
        id = getIntent().getStringExtra("id");
        path = getIntent().getStringExtra("path");
        intoFlag = getIntent().getIntExtra("intoFlag",0);
        userLoginID = SPHelper.getInstance(this).getStringData("userLoginID",null);
    }

    @Override
    protected void setTitleViews() {
        titleText.setText(getResources().getString(R.string.report_title));
    }

    @Override
    protected void setViews() {
        img = (ImageView) findViewById(R.id.activity_report_img);
        etContent = (EditText) findViewById(R.id.activity_report_et);
        tvSubmit = (TextView) findViewById(R.id.activity_report_tv_submit);

        tvSubmit.setOnClickListener(this);

        ImageLoader.getInstance().displayImage(path,img);
    }

    @Override
    protected void doClickAction(int viewId) {
        super.doClickAction(viewId);
        switch (viewId){
            case R.id.title_ll_back:
                finish();
                AnimUtil.pushRightInAndOut(this);
                break;
            case R.id.activity_report_tv_submit:
                strContent = etContent.getText().toString().trim();
                if(TextUtils.isEmpty(strContent)){
                    showToast("请填写举报理由");
                } else {
                    dorequestReport();
                }
                break;
        }
    }

    private void dorequestReport(){
        showLoading();
        params = new AjaxParams();
        if(intoFlag == 0){
            params.put("commentsId",id+"");
            params.put("reportType","comment");
        } else if(intoFlag == 1){
            params.put("activityId",id+"");
            params.put("reportType","activity");
        } else if(intoFlag == 2){
            params.put("activityId",id+"");
            params.put("reportType","picture");
        }
        params.put("content",strContent);

        LogUtil.e(params.toString()+"------");
        httpRequest.addHeader("Cookie", "userLoginID=" + userLoginID);
        httpRequest.post(Urls.url_report,params,callBack,0);
    }

    @Override
    protected void handlerBean(int requestCode, BaseBean baseBean) {
        super.handlerBean(requestCode, baseBean);
        if(baseBean.success){
            finish();
            AnimUtil.pushRightInAndOut(this);
        } else {
            if(!TextUtils.isEmpty(baseBean.errMsg)){
                showToast(baseBean.errMsg);
            }
        }
    }
}
